/*************************************************************************************************
 * <pre>
 * @包路径：   BaseModal.js
 * @版权所有： 北京数字医信科技有限公司 (C) 2020
 *
 * @类描述:
 * @版本:       V4.0.0
 * @作者        daizhenhong
 * @创建时间    2020/3/15 11:43 上午
 *
 * @修改记录：
 -----------------------------------------------------------------------------------------------
 ----------- 时间      |   修改人    |     修改的方法       |         修改描述   ---------------
 -----------------------------------------------------------------------------------------------
 </pre>
 ************************************************************************************************/

import {bus} from '../bus'

class BaseModal {
  constructor(showClose, mes, duration) {
    this.showClose = showClose // 私有属性关闭弹框
    this.mes = mes // 私有属性消息
    this.duration = duration // 私有属性时间
  }
}

class SucBaseModal extends BaseModal {
  // eslint-disable-next-line no-useless-constructor
  constructor(showClose, mes, duration) {
    super(showClose, mes, duration)
  }

  showMsg() {
    return bus.$message.success({
      showClose: this.showClose,
      message: this.mes.toString(),
      duration: this.duration
    })
  }

  showNotifyMsg() {
    return bus.$notify({
      title: '成功',
      message: this.mes,
      type: 'success'
    })
  }
}

class ErrBaseModal extends BaseModal {
  // eslint-disable-next-line no-useless-constructor
  constructor(showClose, mes, duration) {
    super(showClose, mes, duration)
  }

  showMsg() {
    return bus.$message.error({
      showClose: this.showClose,
      message: this.mes.toString(),
      duration: this.duration
    })
  }

  showNotifyMsg() {
    return bus.$notify.error({
      title: '错误',
      message: this.mes
    })
  }
}

// 顶部消息提示
const SuccessBase = (mes) => {
  return new SucBaseModal(true, mes, 2000).showMsg()
}
const ErrBase = (mes) => {
  return new ErrBaseModal(true, mes, 2000).showMsg()
}
// 右侧消息提示
const SuccessNotify = (mes) => {
  return new SucBaseModal(true, mes, 2000).showNotifyMsg()
}
const ErrNotify = (mes) => {
  return new ErrBaseModal(true, mes, 2000).showNotifyMsg()
}
const ApiRequest = (req) => {
  if (req.status !== '0') {
    // ErrBase(req.message)
    ErrBase(req.message + '，错误码：' + req.status)
    if (req.message === '用户未登录') {
      bus.$emit('goto', '/login')
      return false
    }
    return false
  } else {
    return true
  }
}
const ApiRequestS = (req) => {
  if (req.status !== '0') {
    // ErrBase(req.message)
    if (req.message === '用户未登录') {
      bus.$emit('goto', '/login')
      return false
    }
    return false
  } else {
    return true
  }
}
export {
  ApiRequest,
  ApiRequestS,
  SuccessBase,
  ErrBase,
  SuccessNotify,
  ErrNotify
}
